import { Component } from '@angular/core';
import { NavController, AlertController, NavParams } from 'ionic-angular';
import { AuthService } from '../../../../providers/auth-service';
import { OrderService } from '../../../../providers/order-service';
import { DictionaryService } from '../../../../providers/dictionary-service';


interface FileReaderEventTarget extends EventTarget {
    result:string
}

interface FileReaderEvent extends Event {
    target: FileReaderEventTarget;
    getMessage():string;
}
 
@Component({
  selector: 'pages-order-modify',
  templateUrl: 'modify.html'
})
export class OrderModifyPage {
  orderInfo = {
    id: '',
    user_id: '',
    status: 0
  };
  imgFiles = []
  MainBusiness:any
  currentUser:any

  constructor(private nav: NavController, 
    private auth: AuthService,
    private order: OrderService,
    private alertCtrl: AlertController,
    private dict: DictionaryService,
    private param: NavParams
    ) {
    this.orderInfo =  param.get('order')
    this.currentUser = auth.getUserInfo()
    this.MainBusiness =  dict.getByType('business')
  }
 
  public orderPublic() {
    this.order.save(this.orderInfo).then(message => {
      if (message) {
        setTimeout(() => {
          this.showPopup("修改成功", "即将返回");
        })
      } else {
        this.showPopup("Error", "");
      }
    },
    error => {
      this.showPopup("Error", error);
    });
  }

  showPopup(title, text) {
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: text,
      buttons: [
       {
         text: 'OK',
         handler: data => {
           this.nav.popToRoot();
         }
       }
     ]
    });
    alert.present();
  }
}
